package com.hustzp.com.xichuangzhu.poetry;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hustzp.com.xichuangzhu.R;

/**
 * Copyright (C) 2015 The huimai mobile client Project
 * All right reserved.
 *
 * @author: wuzhimin@huimai365.com
 * @date: 2016/6/2 10:33
 * @Description:
 */
public class BaiKeAct extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_baike);
        String url = getIntent().getStringExtra(BaiKeAct.class.getSimpleName());
        WebView webView = (WebView) findViewById(R.id.webview);
        initWebView(webView);
        webView.loadUrl(url);
    }

    private void initWebView(WebView webView) {
        final WebSettings settings = webView.getSettings();
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(false);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        if (Build.VERSION.SDK_INT >= 11) {
            settings.setDisplayZoomControls(false);
        }
        settings.setDefaultTextEncodingName("UTF-8");
        settings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
        /**
         * 解决WebView远程代码执行漏洞，防止360应用市场无法提交
         */
        // graphicContent.removeJavascriptInterface("searchBoxJavaBridge_");
        // graphicContent.removeJavascriptInterface("accessibility");
        // graphicContent.removeJavascriptInterface("accessibilityTraversal");

        webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 内部连接跳转
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {

            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
            }

        });
    }

    public void onClose(View v) {
        finish();
    }
}
